package org.example.customer.service;

import lombok.extern.slf4j.Slf4j;
import org.example.common.model.dto.TestDTO;
import org.example.common.model.po.TestPO;
import org.example.common.service.MQListenerService;
import org.example.customer.dao.TestRepository;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author lsliang
 */
@Slf4j
@Service
public class TestListenerServiceImpl implements MQListenerService<TestDTO>{

    private final TestRepository testRepository;

    private TestListenerServiceImpl(TestRepository testRepository) {
        this.testRepository = testRepository;
    }

    @Override
    @RabbitListener(queues = "queue01")
    public void receive(TestDTO userDTO) {
        log.info("监听到的消息为 = {}", userDTO);
        TestPO userPO = new TestPO();
        BeanUtils.copyProperties(userDTO, userPO);
        testRepository.save(userPO);
    }
}
